package com.scqzy.shengchunqiang.sword2offer.day02;

import com.scqzy.shengchunqiang.structure.ListNode;

import java.util.Objects;

/**
 * @Description: 剑指 Offer 06. 从尾到头打印链表
 * @Author 盛春强
 * @Date 2021/8/9 19:55
 */
public class ReversePrint {
    public int[] reversePrint(ListNode head) {
        ListNode node = head;
        int c = 0;
        while (Objects.nonNull(node)) {
            node = node.next;
            c++;
        }
        int[] res = new int[c];
        for (int i = c; i > 0; i--) {
            res[i-1] = head.val;
            head = head.next;
        }
        return res;
    }
}
